<?php

class Menu implements IObject {

    private $IDMenu;
    private $StNome;
    private $ItOrdem;
    private $EnSubmenu;
    private $StId;

    private $ArSubmenus;

    public function __construct($ArMenuData) {
        $this->IDMenu = $ArMenuData['IDMenu'];
        $this->StNome = $ArMenuData['StNome'];
        $this->ItOrdem = $ArMenuData['ItOrdem'];
        $this->EnSubmenu = $ArMenuData['EnSubmenu'];
        $this->StId = $ArMenuData['StId'];
        $this->ArSubmenus = array();
    }

    public function addSubmenu(Submenu $Submenu) {
        if( $Submenu->isSubitem() ) {
            foreach( $this->ArSubmenus as &$SubmenuItem ) {
                if( $SubmenuItem->getIDSubmenu() == $Submenu->getItSubitem() ) {
                    $SubmenuItem->addSubItem( $Submenu );
                }
            }
        } else {
            $this->ArSubmenus[] = $Submenu;
        }
    }

    public static function getSelected() {
        $Menu = Dracosys::getMainMenu()->getMenuSelected();
        return !empty($Menu) ? $Menu->getStId() : '';
    }

    public function has($Controller, $Action) {
        foreach( $this->ArSubmenus as $Submenu ) {
            if( $Submenu->has($Controller, $Action) ) {
                return true;
            }
        }
        return false;
    }

    public function hasSubmenu() {
        return !empty($this->ArSubmenus);
    }

    public function getIDMenu() {
        return $this->IDMenu;
    }

    public function getStNome() {
        return $this->StNome;
    }

    public function getStId() {
        return $this->StId;
    }

    public function getArSubmenus() {
        return $this->ArSubmenus;
    }

    public function equals(IObject $Object) {

    }
}

?>
